package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {
/*    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("zzz.direct", true, false);
    }

    @Bean
    public Queue queue(){
        return QueueBuilder.durable("zzz.queue").build();
    }*/
/*
    *//**
     * 错误的交换机
     * @return
     *//*
    @Bean
    public DirectExchange errorExchange(){
        return new DirectExchange("error.direct", true, false);
    }

    *//**
     * 错误的队列
     * @return
     *//*
    @Bean
    public Queue errorQueue(){
        return QueueBuilder.durable("error.queue").build();
    }
    *//**
     * 错误队列绑定到错误交换机
     * @return
     *//*
    @Bean
    public Binding binding(DirectExchange errorExchange,Queue errorQueue){
        return BindingBuilder.bind(errorQueue).to(errorExchange).with("error");
    }
    *//**
     * 错误队列绑定到错误交换机
     * @return
     *//*
    @Bean
    public MessageRecoverer messageRecoverer(RabbitTemplate rabbitTemplate){
        return new RepublishMessageRecoverer(rabbitTemplate,"error.direct","error");
    }*/

    @Bean
    public DirectExchange dlExchange(){
        return new DirectExchange("dl.direct", true, false);
    }

    @Bean
    public Queue dlQueue(){
        return QueueBuilder.durable("dl.queue").build();
    }

    @Bean
    public Binding dlbinding(DirectExchange dlExchange,Queue dlQueue){
        return BindingBuilder.bind(dlQueue).to(dlExchange).with("dl");
    }

    @Bean
    public DirectExchange simpleExchange(){
        return new DirectExchange("simple.direct", true, false);
    }
    @Bean
    public Queue simpleQueue(){
        return QueueBuilder.durable("simple.queue")
                .deadLetterExchange("dl.direct")
                .deadLetterRoutingKey("dl")
                .build();
    }
    @Bean
    public Binding simpleBinding(DirectExchange simpleExchange,Queue simpleQueue){
        return BindingBuilder.bind(simpleQueue).to(simpleExchange).with("simple");
    }

//    @Bean
//    public DirectExchange tllExchange(){
//        return new DirectExchange("tll.direct", true, false);
//    }
//    @Bean
//    public Queue tllQueue(){
//        return QueueBuilder.durable("tll.queue")
//                .deadLetterExchange("dl.direct")
//                .deadLetterRoutingKey("dl")
//                .ttl(10000)
//                .build();
//    }
//    @Bean
//    public Binding tllBinding(DirectExchange tllExchange,Queue tllQueue){
//        return BindingBuilder.bind(tllQueue).to(tllExchange).with("tll");
//    }




}
